<template>
  <div>
    <a-carousel autoplay class="my-carousel">
      <img v-for="(item,index) in carouselList" :key="index" v-lazy="item.carouselImgUrl" :alt="item.carouselName" :title="item.carouselName" class="carousel-img" @click="toBlogInfo(item)">
    </a-carousel>
    <blog-list />
  </div>
</template>

<script>
import blogList from '@/views/blog/blog-list'
import BlogList from '../blog/blog-list'
import carouselApi from '../../api/carousel'
export default {
  name: 'Index',
  components: {
    BlogList
  },
  blogList,
  data() {
    return {
      carouselList: []
    }
  },
  created() {
    this.getEnabledCarousels()
  },
  methods: {
    getEnabledCarousels() {
      carouselApi.getList().then(res => {
        if (res.code === 200) {
          this.carouselList = res.data
        }
      })
    },
    toBlogInfo(item) {
      const that = this
      this.$confirm({
        title: '跳转确认',
        content: `是否确定跳转到${item.carouselName}?`,
        onOk() {
          return that.$router.push(item.carouselUrl)
        },
        onCancel() {}
      })
    }
  }
}
</script>

<style>
  .my-carousel{
    width: 100%;
    overflow: hidden;
    height: 432px;
  }
  .carousel-img{
    width: 830px;
    height: auto;
    min-height: 432px;
  }
  .ant-carousel .slick-list {
    position: relative;
    display: block;
    margin: 0;
    padding: 0;
    overflow: hidden;
    height: 432px !important;
  }
</style>
